//
//  AXMySrdzWdzwCell.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/11/10.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "AXMySrdzWdzwCell.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "UITableView+SDAutoTableViewCellHeight.h"

@implementation AXMySrdzWdzwCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self creatView];
        [self setlayout];
    }
    return self;
}




- (void)creatView {
    
    self.bgView = [[UIView alloc]init];
    self.bgView.backgroundColor = [UIColor whiteColor];
    self.bgView.cornerRadius = 5;
    [self.contentView addSubview:self.bgView];
    
    
    /** UIImageView */
    self.titleImageView = [[UIImageView alloc]init];
    self.titleImageView.backgroundColor = [UIColor colorWithHex:0x00ae9d];
    self.titleImageView.image = [UIImage imageNamed:@""];
    [self.bgView addSubview:self.titleImageView];
    
    /** titlelabel */
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.text = @"我的橘子";
    self.titleLabel.font = FONT_FOURTEEN;
    [self.titleImageView  addSubview:self.titleLabel];
    
    /** label */
    self.label = [[UILabel alloc]init];
    self.label.font = FONT_FOURTEEN;
    self.label.textAlignment = NSTextAlignmentLeft;
    self.label.text = @"种植时间  2018-06-20  200亩  间作  绿色食品";
    self.label.textColor = COLOR_Gray;
    [self.bgView addSubview:self.label];
    
    /** 地址 */
    self.addressImageView = [[UIImageView alloc]init];
    self.addressImageView.image = [UIImage imageNamed:@"wdzwDw"];
    [self.bgView addSubview:self.addressImageView];
    
    self.addressBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.addressBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [self.addressBtn setTitle:@"云南省宾川县金牛镇某村" forState:UIControlStateNormal];
    self.addressBtn.titleLabel.font = FONT_FOURTEEN;
    [self.addressBtn setTitleColor:COLOR_Gray forState:UIControlStateNormal];
    [self.bgView addSubview:self.addressBtn];
    
    /** 病害 */
    self.typeLabel = [[UILabel alloc]init];
    self.typeLabel.text = @"病虫草害史";
    self.typeLabel.textColor = COLOR_Gray;
    self.typeLabel.font = FONT_FOURTEEN;
    [self.bgView addSubview:self.typeLabel];
    
    /** 箭头 */
    self.arrowsBtn = [[UIButton alloc]init];
    [self.arrowsBtn setImage:[UIImage imageNamed:@"zhankai"] forState:UIControlStateNormal];
    self.arrowsBtn.titleLabel.font = FONT_FOURTEEN;
    [self.bgView addSubview:self.arrowsBtn];
    
    /** 线 */
    self.lineView = [[UIView alloc]init];
    self.lineView.backgroundColor = COLOR_LINE;
    [self.bgView addSubview:self.lineView];
    
    /** 选择图片 */
    self.selectBtn = [[UIButton alloc]init];
    [self.selectBtn setImage:[UIImage imageNamed:@"zwselect"] forState:UIControlStateNormal];
    [self.bgView addSubview:self.selectBtn];
    
    /** 当前作物 */
    self.zuowuLabel = [[UILabel alloc]init];
    self.zuowuLabel.text = @"当前作物";
    self.zuowuLabel.textColor = COLOR_Gray;
    self.zuowuLabel.font = FONT_FOURTEEN;
    [self.bgView addSubview:self.zuowuLabel];
    
    /** 删除按钮 */
    self.delegateBtn = [[UIButton alloc]init];
    [self.delegateBtn setImage:[UIImage imageNamed:@"grayDelete"] forState:UIControlStateNormal];
    [self.bgView addSubview:self.delegateBtn];
    
    /** 管理按钮 */
    self.manageBtn = [[UIButton alloc]init];
    self.manageBtn.cornerRadius = 5;
    [self.manageBtn addTarget:self action:@selector(manage:) forControlEvents:UIControlEventTouchUpInside];
    self.manageBtn.backgroundColor = COLOR_GREEN;
    [self.manageBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.manageBtn setTitle:@"管理" forState:UIControlStateNormal];
    [self.bgView addSubview:self.manageBtn];
    
    
}

- (void)setlayout {
    
    self.bgView.sd_layout
    .leftSpaceToView(self.contentView, 10)
    .topSpaceToView(self.contentView, 10)
    .widthIs(SCREEN_WIDTH - 20)
    .heightIs(250);
    
    /** UIImageView */
    self.titleImageView.sd_layout
    .leftSpaceToView(self.bgView, 0)
    .topSpaceToView(self.bgView, 0)
    .widthIs(SCREEN_WIDTH)
    .heightIs(44);
    
    /** titlelabel */
    self.titleLabel.sd_layout
    .centerXEqualToView(self.titleImageView)
    .topSpaceToView(self.titleImageView, 0)
    .widthIs(100 )
    .heightIs(44);
    
    /** label */
    self.label.sd_layout
    .leftSpaceToView(self.bgView, 10)
   .topSpaceToView(self.titleImageView, 10)
    .widthIs(SCREEN_WIDTH-20)
    .heightIs(30);
    
    /** 地址 */
    self.addressImageView.sd_layout
    .leftSpaceToView(self.bgView, 10)
    .topSpaceToView(self.label, 10)
    .widthIs(30)
    .heightIs(30);
    
    /** 地址 */
    self.addressBtn.sd_layout
    .leftSpaceToView(self.addressImageView, 10)
    .topSpaceToView(self.label, 10)
    .rightSpaceToView(self.bgView, 10)
    .heightIs(30);
    
    
    /** 病害 */
    self.typeLabel.sd_layout
    .leftSpaceToView(self.bgView, 10)
    .topSpaceToView(self.addressBtn, 10)
    .widthIs(120)
    .heightIs(30);
    
    
    /** 箭头 */
    self.arrowsBtn.sd_layout
    .rightSpaceToView(self.bgView, 10)
    .topSpaceToView(self.addressBtn, 10)
    .widthIs(30)
    .heightIs(30);
    
    
    /** 线 */
    self.lineView.sd_layout
    .leftSpaceToView(self.bgView, 10)
    .topSpaceToView(self.typeLabel, 10)
    .widthIs(SCREEN_WIDTH-20)
    .heightIs(1);
    
    
    /** 选择图片 */
    self.selectBtn.sd_layout
    .leftSpaceToView(self.bgView, 10)
    .topSpaceToView(self.lineView, 10)
    .widthIs(30)
    .heightIs(30);
    
    /** 当前作物 */
    self.zuowuLabel.sd_layout
    .leftSpaceToView(self.selectBtn, 10)
    .topSpaceToView(self.lineView, 10)
    .widthIs(70)
    .heightIs(30);
    
    /** 管理按钮 */
    self.manageBtn.sd_layout
    .rightSpaceToView(self.bgView, 10)
    .topSpaceToView(self.lineView, 10)
    .widthIs(70)
    .heightIs(30);
    
    
    /** 删除按钮 */
    self.delegateBtn.sd_layout
    .rightSpaceToView(self.manageBtn, 10)
    .topSpaceToView(self.lineView, 10)
    .widthIs(30)
    .heightIs(30);
    
    
    
    [self setupAutoHeightWithBottomView:self.bgView bottomMargin:10];
   
    
    
}


#pragma mark - Action

- (void)manage:(UIButton *)btn {
    
    if (self.tapButtonClickedBlock) {
    
        
        self.tapButtonClickedBlock(btn.tag);
    }
    
}

@end
